//------------------------------------------------------------------------
// <copyright file="TaggerControl.cs" company="DevDir">
//   Copyleft (c) DevDir. No rights reserved.
// </copyright>
// <author>Nikita Sharov</author>
//------------------------------------------------------------------------

namespace DevDir.Mp3.Equilibrist.Controls
{
  using System.Data;
  using System.Windows.Forms;

  public partial class TaggerControl : BaseControl
  {
    private BindingSource bindingSource = new BindingSource();
    
    public TaggerControl()
    {
      this.InitializeComponent();
      this.SetUp(this.dataGridView);
      this.SetUpDataBindings();
    }

    public object DataSource
    {
      get { return this.bindingSource.DataSource; }
      set
      {
        if (this.bindingSource.DataSource != value)
        {
          this.bindingSource.DataSource = value;
          this.OnDataSourceChanged();
        }
      }
    }

    protected virtual void OnDataSourceChanged()
    {
      fileDataControl.DataSource = bindingSource;
      metaDataControl.DataSource = bindingSource;
    }

    private void SetUpDataBindings()
    {
      this.dataGridView.AutoGenerateColumns = false;
      this.dataGridView.DataSource = this.bindingSource;

      DataGridViewTextBoxColumn c = new DataGridViewTextBoxColumn();
      c.HeaderText = "Artist";
      c.DataPropertyName = "Artist";
      c.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
      c.FillWeight = 20;      
      this.dataGridView.Columns.Add(c);

      c = new DataGridViewTextBoxColumn();
      c.HeaderText = "Year";
      c.DataPropertyName = "Year";
      c.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
      c.FillWeight = 10;
      this.dataGridView.Columns.Add(c);

      c = new DataGridViewTextBoxColumn();
      c.HeaderText = "Album";
      c.DataPropertyName = "Album";
      c.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
      c.FillWeight = 20;
      this.dataGridView.Columns.Add(c);

      c = new DataGridViewTextBoxColumn();
      c.HeaderText = "Track";
      c.DataPropertyName = "Track";
      c.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
      c.FillWeight = 10;
      this.dataGridView.Columns.Add(c);

      c = new DataGridViewTextBoxColumn();
      c.HeaderText = "Title";
      c.DataPropertyName = "Title";
      c.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
      c.FillWeight = 30;
      this.dataGridView.Columns.Add(c);

      c = new DataGridViewTextBoxColumn();
      c.HeaderText = "Duration";
      c.DataPropertyName = "Duration";
      c.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
      c.FillWeight = 10;
      this.dataGridView.Columns.Add(c);
    }
  }
}

